#ifndef LOGGER_H
#define LOGGER_H

#include <cstdio>
#include <cstdarg>
#include <pthread.h>

/*
 * Logger class - singleton
 */
class Logger
{
	public:
		/*
		 * Level of the log message
		 */
		enum Level 
		{ 
			INFO, // informational
			WARN, // warning
			ERROR, // error
			ERRNO  // like error, but also print string representation of current errno
		};
		
		/*
		 * Returns Logger singleton instance
		 */
		static Logger& getInstance();
		
		/*
		 * opens log file, returns true when success
		 */
		bool setLogFile(const char file_path[]);		
				
		~Logger();	
		
		/*
		 * Log message from dlm
		 * level	- message level
		 * format	- printf-like format
		 */		
		void logDlm(Level level, const char* format, ...);	
		
		/*
		 * Log message from process
		 * pid		- pid of the process that sent the message
		 * message	- message to log
		 */				
		void logProcess(int pid, const char* message);		
	
	private:
		pthread_mutex_t mutex_;					
		FILE* logFile_;
		
		Logger(); // private ctor - singleton
		Logger(const Logger &l); // private cctor - singleton
		Logger& operator=(const Logger &l); // private = op. - singleton
		
		void logPrint(const char* format, ...);		
		void logVPrint(const char* format, va_list &args);			
};

#endif
